package cn.mg.framework.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author hezhaoming
 * @date 2019-10-31
 */

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class PlatformResult implements Result {


    /**
     * 操作是否成功
     */
    private boolean success = CommonCode.SUCCESS.success;

    /**
     * 操作代码
     */
    private String code = CommonCode.SUCCESS.code;

    /**
     * 提示信息
     */
    private String message;

    /**
     * 数据
     */
    private Object data;

    public PlatformResult(ResponseCode resultCode) {
        this.success = resultCode.success();
        this.code = resultCode.code();
        this.message = resultCode.message();
    }

    public PlatformResult(ResponseCode resultCode, Object data) {
        this.success = resultCode.success();
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = data;
    }

    /**
     * 成功
     *
     * @return
     */
    public static PlatformResult success() {
        return new PlatformResult(CommonCode.SUCCESS);
    }

    /**
     * 成功
     *
     * @return
     */
    public static PlatformResult success(Object data) {
        return new PlatformResult(CommonCode.SUCCESS, data);
    }

    /**
     * 失败
     *
     * @return
     */
    public static PlatformResult failure() {
        return new PlatformResult(CommonCode.SERVER_ERROR);
    }

    /**
     * 失败
     *
     * @return
     */
    public static PlatformResult failure(Object data) {
        return new PlatformResult(CommonCode.SERVER_ERROR, data);
    }
}
